<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/themes/default/peasyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/demo/demo.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/coun.css"/>
	<script type="text/javascript" src="<%=path%>/js/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/template.js"></script>
	<script type="text/javascript" src="<%=path%>/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=path%>/js/plugins/jquery.datagrid.js"></script>
	<script type="text/javascript">
		 

				$(function(){

					loadTable();
					loadsettle();
				
				
					  $.ajax({
				           type: "GET",
				           url:'<%=path%>/main/get/skxbs',
						   data : {
									 "cropid":"1",
									 "serialno":"201508192232011"
								},
									async : false,
									success : function(data) {
										var data = eval('(' + data + ')');
									    var num = data.status;
									    if (num == 0) {
											    das=data.data;
											    
											    $("#dd").val(das.date);
											    $("#danju").val(das.no);
											    $("#lsh").val(das.serialno);
											    $("#djs").val(das.djsum);
											    $("#fph").val(das.invoiceno);
											    $("#gkxm").val(das.customer);
											    $("#sjh").val(das.telno);
											    $("#bksj").val(das.cardtime);
											    $("#yhhd").val(das.billmaincol3);
											    $("#hydw").val(das.memcorp);
											    $("#yyjsj").val(das.reservatime);
											    $("#ckd").val(das.outboundorder);
											    $("#fptt").val(das.invoicehead);
									      	
										}else{
											$.messager.alert("","查询失败");
										}

									}
								}); 
				
				
				});
				
				
				

				function loadUser(){
					$.ajax({
						type:"GET",
				    	async: false,
				   	 	url:"<%=path %>/main/get/customer",
				   		data :null,
				   		dataType: "json",
				    	success:function(data){
				    	
				    		var memArchise=data.data;
	
				      		var beans = {			
								list : memArchise
				      		};
							var html = template('memberList', beans);
							document.getElementById('memberNames').innerHTML =html;	
				    				    		
					    	}
					});
				}
						
				function loadTable(){
	
					$.extend($.fn.validatebox.defaults.rules, {    
						length: { validator: function (value, param) {
							
						if(value<=1){
							if((value + '').indexOf('.') != -1){
				            	   var len = $.trim(value).length;
					               return len >= param[0] && len <= param[1];
				            	}
							}
			            },
			                message: "格式错误，请输入正确的折扣率"
			            }
					});  


					
					var ds =[
				{

				"ystype": "1",
				"ysname": "应收"
				},
				{
					"ystype": "0",
					"ysname": "应付"
				}
				];
					
					var as="";
					var xiaofeishuju ="";
					
						$.ajax({
							type:"GET",
					 		async: false,
							url:'<%=path%>/main/get/subinfo',
							dateType:'json',
							data:null,
							success:function(data){
								var result = eval('(' + data + ')');
								as=result.data;
							
								}
							});
						
						$.ajax({
							type:"GET",
					    	async: false,
					   	 	url:"<%=path %>/main/get/localxiaofei",
					   		data :{"cropid":<%=session.getAttribute("cropid")%>},
					   		dataType: "json",
					    	success:function(data){
					    						    		
					    		xiaofeishuju = data.data;		    		
						    	
					    	}
						});
						

					$('#tt').datagrid({
						
						width:924,
						height:350,
						url:'<%=path%>/main/get/skxbss',
		   	    	    queryParams : {
		   				 "cropid":"1",
		   				 "serialno":"201508192232011",
		   			    },
						rownumbers:true,
						selectOnCheck: true,
					    checkOnSelect: true,
						title:'',	
						columns:[[
						{field:'id',title:'序号',width:190,checkbox:true},
			            {  
			                field: 'consumeclass',  
			                title: '消费大类',  //拥有远程数据库
			                width: 100,  
			                formatter: function(value) {  
			                    for (var i = 0; i < xiaofeishuju.length; i++) {  
			                        if (xiaofeishuju[i].consumeclass == value){ 
			                        	
			                        	return xiaofeishuju[i].consumeclass
			                        };  
			                    }  
			                    return value;  
			                },  
			                editor: {  
			                    type: 'combobox',  
			                    options: {  
			                        valueField: 'consumeclass',  
			                        textField: 'consumeclass',  
			                        data: xiaofeishuju,  
			                        required: true,
			                        onSelect:function(rowIndex, rowData){
			                  			
			                        	var row = $("#tt").datagrid('getSelected');
			                        	var rindex = $("#tt").datagrid('getRowIndex', row);	                   
			                        	console.log(row+","+rindex);
			                        	var ed = $("#tt").datagrid('getEditor', {
			                                index: rindex,
			                                field: 'consumeclass'
			                            });
			                        	 var s = $(ed.target).combobox('getText');
			                        	
			                        	$.ajax({
			                				type:"GET",
			                		 		async: false,
			                				url:'<%=path%>/main/get/localzixiaofei',
			                				dateType:'json',
			                				data:{"iname":s},
			                				success:function(data){
			                					
			                					var result = eval('(' + data + ')');
			                				
			                					
			                					var editor = $("#tt").datagrid("getEditor",{index:rindex,field:'project'});
			                					$(editor.target).combobox("loadData",result.data);
			                			
			                					}
			                				});
			                        	}
			                    }  
			                }  
			            },
			            {  
			                field: 'project',  
			                title: '项目',  
			                width: 100,  
			                formatter: function(value) {  
			                    for (var i = 0; i < xiaofeishuju.length; i++) {  
			                        if (xiaofeishuju[i].code == value){ 
			                        	
			                        	return xiaofeishuju[i].codename
			                        };  
			                    }  
			                    return value;  
			                },  
			                editor: {  
			                    type: 'combobox',  
			                    options: {  
			                        valueField: 'projecttype',  
			                        textField: 'projecttype',  
			                        data: xiaofeishuju,  
			                        required: true
			                    }  
			                }  
			            },
			            {field:'subinfo',title:'项目明细',width:100,editor: { type: 'text', options: { required: true } }},
			            {field:'operationDoctor',title:'手术医师',width:100,editor: { type: 'text', options: { required: true } }},
			            {field:'secondDoctor',title:'配台医师',width:100,editor: { type: 'text', options: { required: true } }},
			            {field:'unoperationDoctor',title:'非手术医师',width:100,editor: { type: 'text', options: { required: true } }},
			            {field:'assistantDictor',title:'医师助手',width:100,editor: { type: 'text', options: { required: true } }},
            	        {field:'price',title:'标价',width:100,editor: { type: 'validatebox', options: { required: true} }},
            	        {field:'quantity',title:'数量',width:100,
            	        	editor: { type: 'validatebox', options: { required: true,
            	        							
            	        		} 
            	       		 }
            	        },
            	        {field:'discount',title:'折扣率',width:100,editor: { type: 'validatebox',options:{
            	        	validType:['zhekou','length[1,4]']
            	        }}},
            	        {field:'youhui',title:'优惠金额',width:100,editor: { type: 'validatebox'}},
            	        {field:'priceAfterDiscount',title:'实际消费金额',width:100,editor: { type: 'numberbox',options:{
            	        	precision:"2" ,max:"99999.99",size:"8" ,maxlength:"8"
            	        }}},
            	        {field:'remark',title:'备注',width:100,editor: { type: 'text', options: { required: true } }},	
				        {field:'action',title:'操作',width:90,align:'center',
			                formatter:function(value,row,index){
			                    if (row.editing){
			                        var s = '<a onclick="saverow(this)">保存</a> ';
			                        var c = '<a onclick="cancelrow(this)">取消</a>';
			                        return s+c;
			                    } else {
			                        var e = '<a onclick="editrow(this)">编辑</a> ';
			                        var d = '<a onclick="deleterow(this)">删除</a>';
			                        return e+d;
			                    }
			                }
			            }
						          ]],
						  
						          
						          onBeforeEdit:function(index,row){
							            row.editing = true;
							            updateActions(index);
							        },
							        onAfterEdit:function(index,row){
							            row.editing = false;
							            updateActions(index);
							        },
							        onCancelEdit:function(index,row){
							            row.editing = false;
							            updateActions(index);
							        }
						 
					});	
				

				}
				function updateActions(index){
				    $('#tt').datagrid('updateRow',{
				        index: index,
				        row:{}
				    });
				}
				
				function getRowIndex(target){
				    var tr = $(target).closest('tr.datagrid-row');
				    return parseInt(tr.attr('datagrid-row-index'));
				}
				function editrow(target){
				    $('#tt').datagrid('beginEdit', getRowIndex(target));
					
				    var row = $('#tt').datagrid('getSelected');
				    var index = $('#tt').datagrid('getRowIndex', row);
				    setEditing(index);  
				}
				function deleterow(target){
				    $.messager.confirm('','确定删除？',function(r){
				        if (r){
				            $('#tt').datagrid('deleteRow', getRowIndex(target));
				        }
				    });
				}
				function saverow(target){
				    $('#tt').datagrid('endEdit', getRowIndex(target));
				}
				function cancelrow(target){
				    $('#tt').datagrid('cancelEdit', getRowIndex(target));
				}
				
				function insert(){
					var row = $('#tt').datagrid('getSelected');
					if (row){
						var index = $('#tt').datagrid('getRowIndex', row);
					} else {
						index = 0;
					}
					$('#tt').datagrid('insertRow', {
						index: index,
						row:{
							status:'P'
						}
					});
					$('#tt').datagrid('selectRow',index);
					$('#tt').datagrid('beginEdit',index);
					          
                	  setEditing(index);    
				}
				
				function setEditing(rowIndex){   
					
					var arr=[];
					
					var editors = $('#tt').datagrid('getEditors', rowIndex);   
				    var priceEditor = editors[7];   //价格
				    var amountEditor = editors[8];   //数量
				    var zkEditor = editors[9];		//折扣率
			
				    var yhjine = editors[10];		//优惠金额
				    var zhEditor =editors[11];		//折后金额
				    priceEditor.target.bind('change', function(){   
				        calculate();   
				    });   
				    amountEditor.target.bind('change', function(){   
				        calculate();   
				    });
				    zkEditor.target.bind('change', function(){   
				        calculate();   
				    }); 
				    yhjine.target.bind('change', function(){   
				        calculate();   
				    }); 
				    
				    function calculate(){  
				    	
				    	var price=priceEditor.target.val();//价格
				        var amount=amountEditor.target.val();//数量
				        var zkl =zkEditor.target.val();//折扣率
				        var yh = yhjine.target.val();//优惠金额
				        
				    	
				        if(zkl!=0&&yh!=0){
				        	alert("折扣率和优惠金额只能输一项");
				        }else{
				        
				        if(zkl==0&&yh==0){
				    		var cost = price* amount;
				    		$(zhEditor.target).numberbox('setValue',cost);
				    		$(yhjine.target).val(0);
				    	}else{
				    	
				    	   if(zkl!=0&&yh==0){
				    		var cost = price* amount*zkl;
				  
							$(zhEditor.target).numberbox('setValue',cost);
							
				    	   }
							if(yh!=0&&zkl==0){
						
					    		var cost = price* amount-yh;
					    						    			
					    		$(zhEditor.target).numberbox('setValue',cost);
					    	
								}				    	   
				    		}
				    	}   
				    }    
				    
				} 
				function toDecimal(value){
					 var val = Number(value);
						   if (!isNaN(val)) {//判断是否是非数值
							 
						      if((val + '').indexOf('.') != -1){
						    	  
						    	
								val =parseFloat(val);
									    
									    
						       } 
						    }
					  return  val;    
				}
//====================================================================================
	</script>
	<script>

	var psj="";
	var fs="";
	var websj="";
	var scbsj="";
	var mzsj="";
	var other="";
	 $(function(){	
	    $('#tt1').datagrid({
	        rownumbers:true,
	        width:924,
	        height:250,
	        url:'<%=path%>/main/get/skxb',

	    	 queryParams : {
				 "cropid":"1",
				 "serialno":"201508192232011" 
			},
	        checkOnSelect: true,
	        columns:[[
	            {field:'id',title:'序号',width:60,checkbox: true},
	            {field:'consultationFied',title:'现场咨询',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'consultationTel',title:'电话咨询',width:100,editor: { type: 'text', options: { required: true }}},
	            {field:'consultationSite',title:'网络咨询',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'markingdepa',title:'市场部',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'outpatientNurse',title:'门诊护士',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'billmaincol2',title:'其他部门人员',width:100,editor: { type: 'text', options: { required: true } }},
	            {field:'action',title:'操作',width:90,align:'center',
	                formatter:function(value,row,index){
	                    if (row.editing){
	                        var s = '<a  onclick="saverowb(this)">保存</a> ';
	                        var c = '<a  onclick="cancelrowb(this)">取消</a>';
	                        return s+c;
	                    } else {
	                        var e = '<a  onclick="editrowb(this)">编辑</a> ';
	                        var d = '<a  onclick="deleterowb(this)">删除</a>';
	                        return e+d;
	                    }
	                }
	            }
	        ]],
	        onBeforeEdit:function(index,row){
	            row.editing = true;
	            updateActionsb(index);
	        },
	        onAfterEdit:function(index,row){
	            row.editing = false;
	            updateActionsb(index);
	        },
	        onCancelEdit:function(index,row){
	            row.editing = false;
	            updateActionsb(index);
	        }
	    });
	});
	function updateActionsb(index){
	    $('#tt1').datagrid('updateRow',{
	        index: index,
	        row:{}
	    });
	}
	
	function getRowIndexb(target){
	    var tr = $(target).closest('tr.datagrid-row');
	    return parseInt(tr.attr('datagrid-row-index'));
	}
	function editrowb(target){
	    $('#tt1').datagrid('beginEdit', getRowIndexb(target));
	}
	function deleterowb(target){
	    $.messager.confirm('','删除确定?',function(r){
	        if (r){
	            $('#tt1').datagrid('deleteRow', getRowIndexb(target));
	        }
	    });
	}
	function saverowb(target){
	    $('#tt1').datagrid('endEdit', getRowIndexb(target));
	}
	function cancelrowb(target){
	    $('#tt1').datagrid('cancelEdit', getRowIndexb(target));
	}
	function insertb(){

		var row = $('#tt1').datagrid('getSelected');
		if (row){
			var index = $('#tt1').datagrid('getRowIndex', row);
		} else {
			index = 0;
		}

		$('#tt1').datagrid('insertRow', {
			index: index,
			row:{
				status:'P'
			}
		});

		$('#tt1').datagrid('selectRow',index);

		$('#tt1').datagrid('beginEdit',index);	
	}
//===================================================================================
	</script>
	
	<script>
			
	function loadsettle(){
		var cs="";
		$.ajax({
			type:"GET",
	 		async: false,
			url:'<%=path%>/main/get/localsettles',
			dateType:'json',
			data:{"cropid":<%=session.getAttribute("cropid")%>},
			success:function(data){
				var result = eval('(' + data + ')');
				cs=result.data;
				}
		});
		
	    $('#tt2').datagrid({
	        rownumbers:true,
	        width:411,
	        height:140,
	        url:'<%=path%>/main/get/stinfo',
	    	 queryParams : {
				 "cropid":"1",
				 "serialno":"201508192232011" 
			},
	        checkOnSelect: true,
	        columns:[[
	           {field:'id',title:'序号',width:60,checkbox:true},
	 	       {  
	                field: 'settlement',  
	                title: '结算方式',  
	                width: 100,  	          
	                editor: {  
	                    type: 'combobox',  
	                    options: {  
	                        valueField: 'settlement',  
	                        textField: 'settlement',  
	                        data: cs,  
	                        required: true,
	                    }  
	                }  
	            }, 
	            {field:'mingxi',title:'明细',width:60,editor: { type: 'text', options: { required: true } }},
	            {field:'amount',title:'金额',width:60,editor: { type: 'numberbox', options:{required: true,
    	        	precision:"2" ,max:"99999.99",size:"8" ,maxlength:"8"
    	        } }},
	            {field:'tips',title:'备注',width:60,editor: { type: 'text', options: { required: true } }},
	            {field:'action',title:'操作',width:70,align:'center',
	                formatter:function(value,row,index){
	                    if (row.editing){
	                        var s = '<a  onclick="saverowc(this)">保存</a> ';
	                        var c = '<a  onclick="cancelrowc(this)">取消</a>';
	                        return s+c;
	                    } else {
	                        var e = '<a  onclick="editrowc(this)">编辑</a> ';
	                        var d = '<a  onclick="deleterowc(this)">删除</a>';
	                        return e+d;
	                    }
	                }
	            }
	        ]],
	        onBeforeEdit:function(index,row){
	            row.editing = true;
	            updateActionsc(index);
	        },
	        onAfterEdit:function(index,row){
	            row.editing = false;
	            updateActionsc(index);
	        },
	        onCancelEdit:function(index,row){
	            row.editing = false;
	            updateActionsc(index);
	        },
	        onEndEdit:function(rowIndex, rowData, changes){
		      
		        
		    }
	    });
	}
//===================================================================================
	function updateActionsc(index){
	    $('#tt2').datagrid('updateRow',{
	        index: index,
	        row:{}
	    });
	}
	
	function getRowIndexc(target){
	    var tr = $(target).closest('tr.datagrid-row');
	    return parseInt(tr.attr('datagrid-row-index'));
	}
	function editrowc(target){
	    $('#tt2').datagrid('beginEdit', getRowIndexb(target));
	}
	function deleterowc(target){
	    $.messager.confirm('','确定删除?',function(r){
	        if (r){
	            $('#tt2').datagrid('deleteRow', getRowIndexb(target));
	        }
	    });
	}
	function saverowc(target){
	    $('#tt2').datagrid('endEdit', getRowIndexb(target));
	}
	function cancelrowc(target){
	    $('#tt2').datagrid('cancelEdit', getRowIndexb(target));
	}
	function insertC(){
		var row = $('#tt2').datagrid('getSelected');
		if (row){
			var index = $('#tt2').datagrid('getRowIndex', row);
		} else {
			index = 0;
		}
		$('#tt2').datagrid('insertRow', {
			index: index,
			row:{
				status:'P'
			}
		});
		$('#tt2').datagrid('selectRow',index);
		$('#tt2').datagrid('beginEdit',index);
	}
//===================================================================================
	</script>
		
	<script>
	
	$(function(){
		 //自定义1个combogrid编辑器
		 $.extend($.fn.datagrid.defaults.editors, {
		
			    combogrid: {			
			        init: function(container, options){			
			            var input = $('<input id="cc" type="text" class="datagrid-editable-input">').appendTo(container);
			           	
			            input.combogrid(options);		
			            return input;			
			        },
			        
			        destroy: function(target){			
			            $(target).combogrid('destroy');		
			        },
		
			        getValue: function(target){			
			            return $(target).combogrid('getValue');		
			        },
			
			        setValue: function(target, value){		
			            $(target).combogrid('setValue', value);			
			        },
			        setValues: function(target, values){		
			            $(target).combogrid('setValues', values);			
			        },
			
			        resize: function(target, width){		
			            $(target).combogrid('resize',width);			
			        }
			
			    }
			
			});   

		
		
		var es =[
	{

	"ystype": "1",
	"ysname": "应收"
	},
	{
		"ystype": "0",
		"ysname": "应付"
	}
	];
		
		var  gssj="";
				
		$('#tt3').datagrid({
			
			width:463,
			height:140,
			url:'<%=path%>/main/get/rminfo',
	    	 queryParams : {
				 "cropid":"1",
				 "serialno":"201508192232011" 
			},

			rownumbers:true,
			selectOnCheck: true,
		    checkOnSelect: true,
			title:'',	
			columns:[[
			{field:'id',title:'序号',width:190,checkbox:true},
	         {  
                field: 'type',  
                title: '类型(其他应收应付)',  
                width: 130,  
           
                editor: {  
                    type: 'combobox',  
                    options: {  
                        valueField: 'ysname',  
                        textField: 'ysname',  
                        data: es,  
                        required: true,
                        onSelect:function(rowIndex, rowData){
			                  
                        	var row = $("#tt3").datagrid('getSelected');
                        	var rindex = $("#tt3").datagrid('getRowIndex', row);
                   
                        	var ed1 = $("#tt3").datagrid('getEditor', {
                                index: rindex,
                                field: 'type'
                            });
                   
                        	  var s = $(ed1.target).combobox('getValue');
                        
                        	  //本地proinfo表
                        	$.ajax({
                				type:"GET",
                		 		async: false,
                				url:'<%=path%>/rm/crp',
                				dateType:'json',
                				data:{"buytype":s,"cropid":<%=session.getAttribute("cropid")%>},
                				success:function(data){
                				
                				 var result = eval('(' + data + ')');	
                				
                				 var editor = $("#tt3").datagrid("getEditor",{index:rindex,field:'corp'});
                				$(editor.target).combobox("loadData",result.data); 
                			
                					}
                				});
                        	}
                    }  
                }  
            },
            {  
                field: 'corp',  
                title: '公司',  
                width: 100,  
               
                editor: {  
                    type: 'combobox',  
                    options: {  
                        valueField: 'corp',  
                        textField: 'corp',                         
                        required: true,
                        
                        onSelect:function(rowIndex, rowData){
			                  
                        	var row = $("#tt3").datagrid('getSelected');
                        	var rindex = $("#tt3").datagrid('getRowIndex', row);
                   
                        	var ed = $("#tt3").datagrid('getEditor', {
                                index: rindex,
                                field: 'corp'
                            });
                        	 gssj="";
                        	 gssj = $(ed.target).combobox('getText');
                    
                        	}
                    } 
            
                }  
            },
            //{field:'productid',title:'公司',name:'productId',width:100}, 
            	{field:'amount',title:'金额',width:100,editor: { type: 'numberbox', options:{required: true,
    	        	precision:"2" ,max:"99999.99",size:"8" ,maxlength:"8"
    	        } }},
	            {field:'action',title:'操作',width:70,align:'center',
	                formatter:function(value,row,index){
	                    if (row.editing){
	                        var s = '<a  onclick="saverowd(this)">保存</a> ';
	                        var c = '<a  onclick="cancelrowd(this)">取消</a>';
	                        return s+c;
	                    } else {
	                        var e = '<a  onclick="editrowd(this)">编辑</a> ';
	                        var d = '<a  onclick="deleterowd(this)">删除</a>';
	                        return e+d;
	                    }
	                }
	            }
	        ]],
	        onBeforeEdit:function(index,row){
	        	
	            row.editing = true;
	            updateActionsd(index);
	        },
	        onAfterEdit:function(index,row){
	            row.editing = false;
	            updateActionsd(index);
	            
	        },
	        onCancelEdit:function(index,row){
	        	
	            row.editing = false;
	            updateActionsd(index);

	        },
	        onEndEdit:function(rowIndex, rowData, changes){
	        /* 	var fs= $('#cc').combogrid('getValues'); */
	        	
	        	rowData.productid = gssj;
	        	
	        }
	    });
		
	});
	function updateActionsd(index){
	    $('#tt3').datagrid('updateRow',{
	        index: index,
	        row:{}
	    });
	}
	
	function getRowIndexd(target){
	    var tr = $(target).closest('tr.datagrid-row');
	    return parseInt(tr.attr('datagrid-row-index'));
	}
	function editrowd(target){
	    $('#tt3').datagrid('beginEdit', getRowIndexd(target));
	}
	function deleterowd(target){
	    $.messager.confirm('','确定删除?',function(r){
	        if (r){
	            $('#tt3').datagrid('deleteRow', getRowIndexd(target));
	        }
	    });
	}
	function saverowd(target){
	    $('#tt3').datagrid('endEdit', getRowIndexd(target));  
	}
	function cancelrowd(target){
	    $('#tt3').datagrid('cancelEdit', getRowIndexb(target));
	}
	function insertd(){
		var row = $('#tt3').datagrid('getSelected');
		if (row){
			var index = $('#tt3').datagrid('getRowIndex', row);
		} else {
			index = 0;
		}
		$('#tt3').datagrid('insertRow', {
			index: index,
			row:{
				status:'P'
			}
		});
		$('#tt3').datagrid('selectRow',index);
		$('#tt3').datagrid('beginEdit',index);
	}
	</script>
	<script>
		function saveshuju(){
	
			var dd = $('#dd').datebox('getValue'); 
			var danju = document.getElementById('danju').value;
			var lsh = document.getElementById('lsh').value;
			var fph =  document.getElementById('fph').value;
			
			console.log(dd+","+danju+","+lsh+","+fph);
			
			var name = $("#memberNames").textbox("getValue");
			var phone = document.getElementById('phone').value;
			var banka = $('#banka').datebox('getValue'); 
			var youhui = document.getElementById('youhui').value;
			var huiyuan = document.getElementById("huiyuan").value;
			var yuyue = $('#yuyue').datebox('getValue'); 
			var chuku = document.getElementById('chuku').value;
			var fptt = document.getElementById('fptt').value;
			console.log(name+","+huiyuan+","+phone+","+banka+","+youhui+","+yuyue+","+chuku+","+fptt);
		
	
			 //获取tt表里面的数据
			 var g21="";
			 var g22="";
			 var g23="";
			 var g24="";
			 var g25="";
			 var g26="";
			 var g27="";
			 var g28="";
			 var g29="";
			 var g210="";
			 var g211="";
			 var g212="";

				var checkedItems = $('#tt').datagrid('getChecked');

				var  price=0;
				var s1 ="";
				var s2 ="";
				var s3 ="";
				var s4 ="";
				var s5 ="";
				var s6 ="";
				var s7 ="";
				var s8 ="";
				var s9 ="";
				var s10 ="";
				var s11 ="";
				var s12 ="";
				
				var guodu1="";
				var guodu2="";
				var guodu3="";
				var guodu4="";
				var guodu5="";
				var guodu6="";
				var guodu7="";
				var guodu8="";
				$.each(checkedItems, function(index, item){
					
					price+=Number(item.zhehoupr);
					
					s1+=s1==""?item.xiaofei:","+item.xiaofei;
					s2+=s2==""?item.xiangmu:","+item.xiangmu;
					
					if(item.xmmingxi==""){
						guodu1="1"
					}else{
						guodu1=item.xmmingxi
					}
					s3+=guodu1+","
					
					
					
					if(item.shoushudc1==""){
						guodu2="1"
					}else{
						guodu2=item.shoushudc1
					}
					s4+=guodu2+","
					
					
					if(item.shoushudc2==""){
						guodu3="1"
					}else{
						guodu3=item.shoushudc2
					}
					s5+=guodu3+","
					
					
					if(item.shoushudc3==""){
						guodu4="1"
					}else{
						guodu4=item.shoushudc3
					}
					s6+=guodu4+","
					
					
					if(item.shoushudc4==""){
						guodu5="1"
					}else{
						guodu5=item.shoushudc4
					}
					s7+=guodu5+","
					
				
					s8+=s8==""?item.biaojia:","+item.biaojia;
					s9+=s9==""?item.shuliang:","+item.shuliang;
				
		

					if(item.zhekou==""){
						guodu6="1"
					}else{
						guodu6=item.zhekou
					}
					s10+=guodu6+","
					
					if(item.zhehoupr==""){
						guodu7="1"
					}else{
						guodu7=item.zhehoupr
					}
					s11+=guodu7+","
					
					
					if(item.beizhu==""){
						guodu8="1"
					}else{
						guodu8=item.beizhu
					}
					s12+=guodu8+","
					
					});
				
				g21=s1;
				g22=s2;
				g23=s3;
				g24=s4;
				g25=s5;
				g26=s6;
				g27=s7;
				g28=s8;
				g29=s9;
				g210=s10;
				g211=s11;
				g212=s12;
				console.log(g21+"||"+g22+"||"+g23+"||"+g24+"||"+g25+"||"+g26+"||"+g27+"||"+g28+"||"+g29+"||"+g210+"||"+g211+"||"+g212+"||");
		
				toDecimal(price);
				console.log(price);
				$("#sum").val(price); 
			
			
			
			//获取tt1表里面的数据
			var g1="";
			var g2="";
			var g3="";
			var g4="";
			var g5="";
			var g6="";
	
			var checkedItems = $('#tt1').datagrid('getChecked');
				$.each(checkedItems, function(index, item){
					g1+=g1==""?item.xczx:","+item.xczx;
					g2+=g2==""?item.phonezx:","+item.phonezx;
					g3+=g3==""?item.webzx:","+item.webzx;
					g4+=g4==""?item.scb:","+item.scb;
					g5+=g5==""?item.mznurse:","+item.mznurse;
					g6+=g6==""?item.otherpp:","+item.otherpp;	
					});
			console.log(g1+"!"+g2+"!"+g3+"!"+g4+"!"+g5+"!"+g6);
				
				
			
			//获取tt2表格里面的数据
			var g31="";
			var g32="";
			var g33="";
			var g34="";
			
				var checkedItems = $('#tt2').datagrid('getChecked');
			
				var jine=0;
				var s1 ="";
				var s2 ="";
				var s3 ="";
				var s4 ="";
				
				var guodu9="";
				var guodu10="";
				$.each(checkedItems, function(index, item){
					jine+=Number(item.jine);
					
					

					s1+=s1==""?item.settlement:","+item.settlement;
					
					
					
					if(item.mingxi==""){
						guodu9="1"
					}else{
						guodu9=item.mingxi
					}
					s2+=guodu9+","
					
				
				
					s3+=s3==""?item.jine:","+item.jine;
				
			
					if(item.beizhu==""){
						guodu10="1"
					}else{
						guodu10=item.beizhu
					}
					s4+=guodu10+","
					
					});
				
					g31=s1;
					g32=s2;
					g33=s3;
					g34=s4;
					
			console.log(jine+"$$");
			
					//获取tt3表里面的数据
					 var g41="";
					 var g42="";
					 var g43="";
			
						var checkedItems = $('#tt3').datagrid('getChecked');
				
						var s1="";
						var s2="";
						var s3="";
						
						var jines1=0;//应收金额
						var jines0=0;//应付金额
						
						$.each(checkedItems, function(index, item){
							
							 if(item.buytype=="应付"){
								 jines0+=Number(item.jines);
								
							}
							if(item.buytype=="应收"){
								 jines1+=Number(item.jines);
							} 
							
							
							
							s1+=s1==""?item.buytype:","+item.buytype;
							s2+=s2==""?item.productid:","+item.productid;
							s3+=s3==""?item.jines:","+item.jines;			
					
						});
						
						g41=s1;
						g42=s2;
						g43=s3;
					console.log(jines0+"***"+jines1);
			
			
			console.log(g31+"||"+g32+"||"+g33+"||"+g34);
			console.log(g41+"||"+g42+"||"+g43+"||");
				
			
			 if(dd==null||dd==""||name==null||name==""){
				
				alert("请完善数据!");
			}else{		
				if(price+jines0==jine+jines1){								
				 $.ajax({
							type:"GET",
					    	async: false,
					   	 	url:"<%=path %>/lbs/save/billmain",
					   		data :{"dd":dd,"danju":danju,"lsh":lsh,"fph":fph,"name":name,"phone":phone,"banka":banka,"youhui":youhui,"huiyuan":huiyuan,"yuyue":yuyue,"chuku":chuku,"fptt":fptt,"g1":g1,"g2":g2,"g3":g3,"g4":g4,"g5":g5,"g6":g6,"g21":g21,"g22":g22,"g23":g23,"g24":g24,"g25":g25,"g26":g26,"g27":g27,"g28":g28,"g29":g29,"g210":g210,"g211":g211,"g212":g212,"g31":g31,"g32":g32,"g33":g33,"g34":g34,"g41":g41,"g42":g42,"g43":g43},
					   		dataType: "json",
					    	success:function(data){
					    	
					    		console.log(data);
					    	
					    		var status = data.data;
					    		if(status=='插入成功'){
					    			alert("保存成功!");
					    			}
								if(status=='保存失败'){
					   				alert("保存失败!");
					   				}
								if(status=="1"){
					   				alert("有重复!");
					   			}
						    }
					   			
	
							});  

				}else{
					alert("价格不平，请重新计算");
				}

			} 
		}
		
		function validatemobile(){
			var va =document.getElementById('phone').value;
			var telReg = !!va.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
			//如果手机号码不能通过验证
			if(telReg == false){
			 alert("请输入正确手机号码!");
			}
		}
		
		function fangqi(){
			var r=confirm("确定放弃吗?"); 
			if(r==true){
				
				$.ajax({
					type:"GET",
			    	async: false,
			   	 	url:"<%=path%>/ls/fangqi",
			   		data :null,
			   		dataType: "json",
			    	success:function(data){
			      		
			      		var num = data.status
			      		
			      		if(num!=0){
			      			window.location.href="<%=path%>/ls/get/ls";
			      			console.log("%%");
			      		}
			    	}
				});
				
				
			}
		}
	</script>
<style>
	#div1{

		float: left;
	
	}	
		#div2{
		margin-left:  50px;  
		float: left;
	
	}	
</style>
<title>无标题文档</title>
</head>

<body>
<div class="accountbox">
<h2>账套名称</h2>
<div class="titbtn"><!-- <a href="#">审核</a> --><a href="<%=path%>/ls/get/ls">增加</a><!-- <a href="#">作废</a> --><!-- <a href="#">修改</a> --><a href="#" onclick="fangqi()">放弃</a><a href="#" onclick="saveshuju()">保存</a></div>
<div class="dateof">
<ul>
<li><label>日期</label><input id="dd" type="text" /></li>
<li><label>单据号</label><input id="danju" type="text" /></li>
<li><label>流水号</label><input id="lsh" type="text" /></li>
<li><label>发票号</label><input id="fph" type="text" /></li>
</ul>
</div>
<h3>收款单</h3>
<div class="customerName wrapbored">
 <ul>
  <li><label>顾客姓名</label><input id="gkxm" type="text" />
				
				
</li>
  <li><label>手机号码</label><input type="text" id="sjh"/></li>
  <li><label>办卡时间</label><input id="bksj" type="text" ></li>
  <li><label>优惠活动</label><input type="text" id="yhhd" /></li>
  <li><label>会员单位</label><input type="text" id="hydw" /></li>
  <li><label>预约金时间</label><input  type="text" id="yyjsj"/></li>
  <li><label>出库单</label><input  type="text" id="ckd"/></li>
  <li><label>发票抬头</label><input type="text" id="fptt" /></li>
 </ul>
</div>

</div>
</body>
</html>
    